package expert006;

import org.springframework.context.ApplicationContext;
//import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;

public class Driver {
	private static String basePath;
	
	static {
		basePath = StringUtils.cleanPath(ClassUtils.classPackageAsResourcePath(Driver.class)) + "/";
	}
	
	public static void main(String[] args) {
		//ApplicationContext context = new FileSystemXmlApplicationContext("/src/main/java/expert006/expert.xml");
		ApplicationContext context = new GenericXmlApplicationContext(basePath  + "expert.xml");
		
		Car car = (Car)context.getBean("car");

		System.out.println(car.getTireBrand());
	}
}

/**
	설정 파일이 경로 손쉽게 찾기 (토비의 스프링 3.0 p786)
	
	Static 메소드 내부에서
	
	String basePath = StringUtils.cleanPath(ClassUtils.classPackageAsResourcePath(Driver.class)) + "/";
	ApplicationContext context = new GenericXmlApplicationContext(basePath  + "expert.xml");
	
	Instance 메소드 내부에서

	String basePath = StringUtils.cleanPath(ClassUtils.classPackageAsResourcePath(getClass())) + "/";
	ApplicationContext context = new GenericXmlApplicationContext(basePath  + "expert.xml");
*/